package com.test.suanfa;

public class 冒泡排序 {
    static int[] a = {7, 6, 5, 4, 3, 2, 1};

    public static void main(String[] args) {
        fn4();
    }

    public static void fn4() {
        int len = a.length;
        for (int i = 0; i < len; i++) {
            for (int j = 1; j < len - i; j++) {
                if (a[j - 1] > a[j]) {
                    int tmp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = tmp;
                }
            }
        }
        System.out.println(a);
    }

    public static void fn3() {
        int len = a.length;
        for (int i = 0; i < len; i++) {
            for (int j = 1; j < len - i; j++) {
                if (a[j - 1] > a[j]) {
                    int tmp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = tmp;
                }
            }
        }
        System.out.println(a);
    }

    public static void fn2() {
        int len = a.length;
        for (int i = 0; i < len; i++) {
            for (int j = 1; j < len - i; j++) {
                if (a[j - 1] > a[j]) {
                    int tmp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = tmp;
                }
            }
        }
        System.out.println(a);
    }

    public static void fn1() {

        int n = a.length;
        int i, j;

        for (i = 0; i < n; i++) {//表示n次排序过程。
            for (j = 1; j < n - i; j++) {
                if (a[j - 1] > a[j]) {//前面的数字大于后面的数字就交换
                    //交换a[j-1]和a[j]
                    int temp;
                    temp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = temp;
                }
            }
        }
        System.out.println(a);
    }
}
